package com.talent.typehandlers;

import com.talent.domain.PhoneNumber;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by zhumenglong on 2017/6/27.
 */
public class PhoneTypeHandler extends BaseTypeHandler<PhoneNumber>{

    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, PhoneNumber phoneNumber, JdbcType jdbcType) throws SQLException {
        preparedStatement.setString(i,phoneNumber.getAsString());
    }

    @Override
    public PhoneNumber getNullableResult(ResultSet resultSet, String columnName) throws SQLException {
        return new PhoneNumber(resultSet.getString(columnName));
    }

    @Override
    public PhoneNumber getNullableResult(ResultSet resultSet, int columnIndex) throws SQLException {
        return new PhoneNumber(resultSet.getString(columnIndex));
    }

    @Override
    public PhoneNumber getNullableResult(CallableStatement callableStatement, int columnIndex) throws SQLException {
        return new PhoneNumber(callableStatement.getString(columnIndex));
    }
}
